package com.example.demo2.mapper;

import com.example.demo2.entity.Emp;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EmpMapper {
    //查询用户信息
    @Select("select * from emp where id=#{id}")
    public Emp getEmp(int id);

    // 根据用户名查询用户信息
    @Select("select * from emp where username=#{username}")
    public List<Emp> getUserByUsername(String username);

    // limit 和offset 实现分段查询 limit表示每页显示多少条 offset显示表示从第几条开始查
    @Select("select * from emp limit #{limit} offset #{offset}")
    public List<Emp> getUserByPage1(@Param("limit")int limit,@Param("offset")int offset);

    // 分页
    @Select("select * from emp limit #{start},#{size}")
    public List<Emp> getUserByPage(@Param("start") int start, @Param("size")int size);

    //增
    @Insert("INSERT INTO emp (username,name,gender) VALUES (#{username},#{name},#{gender})")
    public boolean insertUser(@Param("username")String username, @Param("name")String name, @Param("gender")short gender);
    //删
    @Delete("DELETE FROM emp WHERE id = #{id}")
    int deleteEmpById(int id);
    //改
    @Update("UPDATE emp SET username = #{username}, name = #{name}, gender = #{gender} WHERE id = #{id}")
    int updateEmpById(@Param("id") int id, @Param("username") String username, @Param("name") String name, @Param("gender") short gender);




}
